package jgrit.gui;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.WindowConstants;

import jgrit.gui.factory.UIFactory;
import jgrit.options.OptionCollection;

import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class AreaOptionsPanel extends javax.swing.JPanel {

	/**
	 * Auto-generated serialization version ID
	 */
	private static final long serialVersionUID = -4720347263511833965L;

	private JTextField leftTextField;
	private JCheckBox customAreaCheckBox;
	private JTextField heightTextField;
	private JTextField widthTextField;
	private JTextField topTextField;

	/**
	* Auto-generated main method to display this 
	* JPanel inside a new JFrame.
	*/
	public static void main(String[] args) {
		JFrame frame = new JFrame("Area");
		frame.getContentPane().add(new AreaOptionsPanel());
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
	}
	
	@Deprecated
	public AreaOptionsPanel() {
		this(new OptionCollection());
	}
	
	public AreaOptionsPanel(OptionCollection options) {
		super();
		initGUI(options);
	}
	
	private void initGUI(OptionCollection options) {
		try {
			FormLayout thisLayout = new FormLayout(
					"max(p;5dlu), max(p;5dlu), 5dlu, max(p;20dlu):grow, max(p;5dlu), max(p;5dlu), 5dlu, max(p;20dlu):grow, 5dlu", 
					"max(p;5dlu), max(p;5dlu), max(p;5dlu), max(p;5dlu), max(p;5dlu), max(p;5dlu), 5dlu:grow");
			this.setLayout(thisLayout);
			{
				final JLabel leftLabel = new JLabel();
				this.add(leftLabel, new CellConstraints("2, 4, 1, 1, default, default"));
				leftLabel.setText("Left:");
			}
			{
				final JLabel topLabel = new JLabel();
				this.add(topLabel, new CellConstraints("2, 6, 1, 1, default, default"));
				topLabel.setText("Top:");
			}
			{
				leftTextField = new JTextField();
				this.add(leftTextField, new CellConstraints("4, 4, 1, 1, default, default"));
				leftTextField.setText("0");
				leftTextField.setEnabled(false);
				UIFactory.attachOptionChecked(options.areaLeft, leftTextField);
			}
			{
				topTextField = new JTextField();
				this.add(topTextField, new CellConstraints("4, 6, 1, 1, default, default"));
				topTextField.setText("0");
				topTextField.setEnabled(false);
				UIFactory.attachOptionChecked(options.areaTop, topTextField);
			}
			{
				final JLabel widthLabel = new JLabel();
				this.add(widthLabel, new CellConstraints("6, 4, 1, 1, default, default"));
				widthLabel.setText("Width:");
			}
			{
				final JLabel heightLabel = new JLabel();
				this.add(heightLabel, new CellConstraints("6, 6, 1, 1, default, default"));
				heightLabel.setText("Height:");
			}
			{
				widthTextField = new JTextField();
				this.add(widthTextField, new CellConstraints("8, 4, 1, 1, default, default"));
				widthTextField.setText("0");
				widthTextField.setEnabled(false);
				UIFactory.attachOptionChecked(options.areaWidth, widthTextField);
			}
			{
				heightTextField = new JTextField();
				this.add(heightTextField, new CellConstraints("8, 6, 1, 1, default, default"));
				heightTextField.setText("0");
				heightTextField.setEnabled(false);
				UIFactory.attachOptionChecked(options.areaHeight, heightTextField);
			}
			{
				customAreaCheckBox = new JCheckBox();
				this.add(customAreaCheckBox, new CellConstraints("2, 2, 7, 1, default, default"));
				customAreaCheckBox.setText(options.areaIsCustom.getName());
				UIFactory.attachOption(options.areaIsCustom, customAreaCheckBox);
				customAreaCheckBox.addActionListener(new ActionListener() {

					public void actionPerformed(ActionEvent e) {
						if (customAreaCheckBox.isSelected()) {
							leftTextField.setEnabled(true);
							topTextField.setEnabled(true);
							widthTextField.setEnabled(true);
							heightTextField.setEnabled(true);
						} else {
							leftTextField.setEnabled(false);
							topTextField.setEnabled(false);
							widthTextField.setEnabled(false);
							heightTextField.setEnabled(false);
						}
					}
					
				});
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
